package Professions;
import java.util.List;
import java.util.Random;

import structures.Pace;
import structures.Passenger;
import structures.Spaceship;
import structures.Status;
/**
 * Engineer: Fixes technical problems that arise with the engines or other parts of the ship.
 * Completes these tasks using fewer resources and less time.
 * 
 * @author Branon Lyle
 */
public class Engineer implements Profession {
	
	private final static String DESCRIPTION = "An Engineer is proficient at fixing technical\n" +
	                                          "problems that arise with engines and other parts\n" +
	                                          "of the ship. When Completed by an Engineer, technical\n" +
	                                          "tasks require fewer resources and less time.";

	public Engineer() {
		
	}
	
	/**
	 * DESCRIPTION Accessor
	 * @return DESCRIPTION
	 */
	public static String getDescription() {
		return DESCRIPTION;
	}
	
	@Override
    public String fixEngines(Spaceship ship) {
		String rv = "";
        Random rnd = new Random();
        int n = rnd.nextInt(100);
        if(n < 25){
        	if(ship.getInventory().getQuantity(4) > 0){
        		ship.getInventory().changeQuantity(4, -1);
        		rv = "Fixed engine with some Duck Tape.";
        	}
        	else{
        		ship.breakEngine();
        		ship.setPace(Pace.SLOW);
        		rv = "Failed to fix engine!";
        	}
        }
        else
        	rv = "Fixed engine without any Duck Tape!";
        ship.fixEngine();
        return rv;
    }

    @Override
    public void fixPeople(Passenger p, Spaceship ship) {
        Random rnd = new Random();
        int n = rnd.nextInt(100);
        if(n < 95)
        	ship.getInventory().changeQuantity(3, -1);
        p.setStatus(Status.HEALTHY);
    }

    @Override
    public void freezePeople(Passenger p, Spaceship ship) {
        Random rnd = new Random();
        int n = rnd.nextInt(100);
        if(n < 5)
        	p.setStatus(Status.DEAD);
        else
        	p.setStatus(Status.CRYOSTASIS);
        ship.getInventory().changeQuantity(5, -20);
    }

    @Override
    public int killPeople(int allies, int enemies, int guns) {
    	Random rnd = new Random();
    	int n = rnd.nextInt(75) + ((1 * allies) - (enemies / 1) + guns);
    	if(n < 5)
    		return allies * 2;
    	else if (n < 15)
    		return allies * 2 - 1;
    	else if (n < 50)
    		return allies + 1;
    	else if (n < 75)
    		return allies - 1;
    	else if (n < 90)
    		return 1;
    	else
    		return 0;
    }
	
	/**
     * String representation of Engineer for use in GUI
     */
	public String toString(){
		return "Engineer";
	}
}
